﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Utils;
using DataHelper;
namespace DAL
{
    public class JJDao
    {
        string tableName = "Wage_Jj";
        public bool Update(SortedDictionary<string, string> sdList)
        {
            return new BuiltSQL().UpdateTable(tableName, sdList);
        }
        public bool Insert(SortedDictionary<string, string> sdList)
        {
            return new BuiltSQL().InsertTable(tableName, sdList);
        }
        public bool Delete(string jjCode)
        {
            return SQLHelper.ExecuteSql("Delete from " + tableName + " Where JJCode='" + jjCode + "'");
        }
        public DataTable GetOneInfo(string jjCode)
        {
            return SQLHelper.ExecuteSqlGetDrToDt("Select * from Wage_Jj where JJCode='" + jjCode + "'");
        }
        public bool IsExist(string jjCode)
        {
            DataTable dt = GetOneInfo(jjCode);
            if (dt.Rows.Count > 0)//如果存在该用户编号
                return true;
            else//否则
                return false;
        }
        public DataTable GetLists(string serWord, string bTime, string eTime, string deptID, string proCode)
        {
            StringBuilder strSQL = new StringBuilder("select * from " + tableName + " Where 1=1 ");
            if (!string.IsNullOrWhiteSpace(serWord))
            {
                strSQL.Append(" and ( EmpCode like '%" + serWord + "%' Or EmpName like '%" + serWord + "%') ");
            }
            //else
           // {
                if (!string.IsNullOrWhiteSpace(deptID)&&deptID!="0")
                    strSQL.Append(" and  DeptID = " + deptID);
                if (!string.IsNullOrWhiteSpace(proCode) && proCode != "0")
                    strSQL.Append(" and  ProCode = '" + proCode+"'");
                if (!string.IsNullOrWhiteSpace(bTime))
                    strSQL.Append(" and JJTime >= '" + bTime + "' ");
                if (!string.IsNullOrWhiteSpace(eTime))
                    strSQL.Append(" and JJTime <= '" + eTime + "'");
            //}

            strSQL.Append(" Order by JJTime DESC");
            return SQLHelper.ExecuteSqlGetDrToDt(strSQL.ToString());
        }
    }
}
